package com.ruoyi.web.controller.his;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.his.domain.HisSupplier;
import com.ruoyi.his.domain.HisManufactor;
import com.ruoyi.his.service.IHisDrugsService;
import com.ruoyi.his.service.IHisSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author shebin
 * @site www.694840063@qq.com
 * @company 扬州绘鑫勤商贸有限公司
 * @create 2021-08-23 20:50
 */

@RestController
@RequestMapping("/his/supplier")
public class hisSupplierController extends BaseController {

    @Autowired
    private IHisSupplierService hisSupplierService;

    /**
     * 获取供应商列表
     * @param supplier
     * @return
     */
    @PreAuthorize("@ss.hasPermi('his:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisSupplier supplier){
        startPage();
        List<HisSupplier> list = hisSupplierService.selectSupplierList(supplier);
        return getDataTable(list);
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:supplier:query')")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable Long supplierId)
    {
        return AjaxResult.success(hisSupplierService.selectSupplierById(supplierId));
    }

    /**
     * 新增供应商
     */
    @PreAuthorize("@ss.hasPermi('his:supplier:add')")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody HisSupplier supplier)
    {
        supplier.setCreateBy(getUsername());
        return toAjax(hisSupplierService.insertSupplier(supplier));
    }

    /**
     * 修改供应商
     */
    @PreAuthorize("@ss.hasPermi('his:supplier:edit')")
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody HisSupplier supplier)
    {
        supplier.setUpdateBy(getUsername());
        return toAjax(hisSupplierService.updateSupplier(supplier));
    }

    /**
     * 删除供应商
     */
    @PreAuthorize("@ss.hasPermi('his:supplier:remove')")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds){
        return toAjax(hisSupplierService.deleteSupplierByIds(supplierIds));
    }

}
